﻿using System;
using System.Collections.Generic;
using System.Text;

namespace twilters
{
    /**
     * Just a simple Tweet POJO
     * 
     * 
     * @author Sigmar Muuga
     */
    public class Tweet
    {
        Dictionary<TweetField, Object> values = new Dictionary<TweetField, Object>();

        public Tweet()
        {
        }

        public Tweet(String screenName, String text):this(screenName, text, "twiltersLogo.jpg") {
 
        }

        public Tweet(String screenName, String text, String profileImage)
        {
            values.Add(TweetField.ScreenName, screenName);
            values.Add(TweetField.Text, text);
            values.Add(TweetField.ProfileImage, profileImage);
        }

        public String FollowerUsername { get; set; }



        public String ScreenName
        {
            get
            {
                return (String)GetFieldValue(TweetField.ScreenName);
            }
            set
            {
                SetFieldValue(TweetField.ScreenName, value);
            }
        }

        public String Text
        {
            get
            {
                return (String)GetFieldValue(TweetField.Text);
            }
            set
            {
                SetFieldValue(TweetField.Text, value);
            } 
        }

        public String ProfileImage
        {
            get
            {
                return (String)GetFieldValue(TweetField.ProfileImage);
            }
            set
            {
                SetFieldValue(TweetField.ProfileImage, value);
            } 
        }

        public DateTime CreateDate { get; set; }

        public String Id { get; set; }

        public override bool Equals(Object obj)
        {
            if (obj == null) return false;
            if (this.GetType() != obj.GetType()) return false;
            Tweet tweet = (Tweet)obj;
            return tweet.Id.Equals(Id);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode() ^ Id.GetHashCode();
        }

        public object GetFieldValue(TweetField field)
        {
            if (values.ContainsKey(field))
            {
                return values[field];
            }
            return null;
        }

        public void SetFieldValue(TweetField field, object value)
        {
            if (values.ContainsKey(field))
            {
                values.Remove(field);
                values.Add(field, value);
            }
        }
    }
}
